//表单序列化
export const serialize = data => {
	let list = [];
	Object.keys(data).forEach(ele => {
		list.push(`${ele}=${data[ele]}`)
	})
	return list.join('&');
};

/**
 * 日期格式化
 * @param {Date} date
 * @param {string} format 格式
 */
export function formatDate(date = new Date(), format = 'YYYY-MM-DD hh:mm:ss') {
	if (!(date instanceof Date)) {
		date = new Date(date);
	}
	const YYYY = date.getFullYear();
	const MM = ('0' + (date.getMonth() + 1)).slice(-2);
	const DD = ('0' + date.getDate()).slice(-2);
	const hh = ('0' + date.getHours()).slice(-2);
	const mm = ('0' + date.getMinutes()).slice(-2);
	const ss = ('0' + date.getSeconds()).slice(-2);

	const result = format
		.replace(/YYYY/, YYYY)
		.replace(/MM/, MM)
		.replace(/DD/, DD)
		.replace(/hh/, hh)
		.replace(/mm/, mm)
		.replace(/ss/, ss);
	return result;
}

/**
 * 获取当前页面路径
 */
export function getCurrentPath() {
	const pages = getCurrentPages();
	const currentPage = pages[pages.length - 1];
	return '/' + currentPage.route;
}
